﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Yipusoft.SecurityEvaluate;
using System.Data;

public partial class Police_SecurityEvaluate_Stat : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindDateList();
            BindData();
        }
    }

    private void BindDateList()
    {
        for (int i = 2008; i <= 2050; i++)
        {
            ListItem li = new ListItem();
            li.Text = i.ToString() + "年";
            li.Value = i.ToString();
            DptYear.Items.Add(li);
        }
        for (int i = 1; i <= 12; i++)
        {
            this.DptMonth.Items.Add(new ListItem(i.ToString() + "月", i.ToString()));
        }
        if (Request.QueryString["year"] == null)
        {
            DptMonth.SelectedValue = DateTime.Now.Month.ToString();
            DptYear.SelectedValue = DateTime.Now.Year.ToString();
        }
        else
        {
            DptMonth.SelectedValue = Request["month"];
            DptYear.SelectedValue = Request["year"];
        }
    }
    void BindData()
    {
        int year = Convert.ToInt32(DptYear.SelectedValue);
        int month = Convert.ToInt32(DptMonth.SelectedValue);
        //人员变动统计
        DataView SodierChanges = Diary.GetDiaryChangesAdminStat(0, year, month).DefaultView;
        SodierChangesChart.Series["人员变动次数"].Points.DataBindXY(SodierChanges, "ShortName", SodierChanges, "count");
        for (int i = 0; i < SodierChanges.Count; i++)
        {
            SodierChangesChart.Series["人员变动次数"].Points[i].Url = "SquadronStat.aspx?Departmentid=" + Convert.ToString(SodierChanges[i]["DepartmentID"]) + "&y=" + DptYear.SelectedValue + "&m=" + DptMonth.SelectedValue;

        }

        //装备变动统计
        DataView DeviceChanges = Diary.GetDiaryChangesAdminStat(1, year, month).DefaultView;
        DeviceChangesChart.Series["装备变动次数"].Points.DataBindXY(DeviceChanges, "ShortName", DeviceChanges, "count");
        for (int i = 0; i < DeviceChanges.Count; i++)
        {
            DeviceChangesChart.Series["装备变动次数"].Points[i].Url = "SquadronStat.aspx?Departmentid=" + Convert.ToString(DeviceChanges[i]["DepartmentID"]) + "&y=" + DptYear.SelectedValue + "&m=" + DptMonth.SelectedValue;

        }
        //外出人员统计
        DataView LeaveChanges = Diary.GetDiaryLeaveAdminStat(year, month).DefaultView;
        LeaveChart.Series["外出人员次数"].Points.DataBindXY(LeaveChanges, "ShortName", LeaveChanges, "count");
        for (int i = 0; i < LeaveChanges.Count; i++)
        {
            LeaveChart.Series["外出人员次数"].Points[i].Url = "SquadronStat.aspx?Departmentid=" + Convert.ToString(LeaveChanges[i]["DepartmentID"]) + "&y=" + DptYear.SelectedValue + "&m=" + DptMonth.SelectedValue;

        }
    }
    protected void DptYear_SelectedIndexChanged(object sender, EventArgs e)
    {
        BindData();
    }
    protected void DptMonth_SelectedIndexChanged(object sender, EventArgs e)
    {
        BindData();
    }
}
